<template>
	<view class="uni-flex uni-column layoutBg">

		<view class="phone uni-flex uni-row">
			<view class="etLabel">
				原密码
			</view>
			<input class="et" placeholder="请输入原密码" v-model="form.password" password/>
		</view>

		<view class="phone uni-flex uni-row">
			<view class="etLabel">
				新密码
			</view>
			<input class="et" placeholder="请输入新密码" v-model="form.newpassword" password/>
		</view>
		
		<view class="phone uni-flex uni-row">
			<view class="etLabel">
				再次密码
			</view>
			<input class="et" placeholder="请输入再次密码" v-model="form.surepassword" password/>
		</view>
		
		<view class="btn-login" @click="onRegister">保存</view>

	</view>
</template>

<script>
	import md5 from '@/utils/md5.js';
	
	export default {
		data() {
			return {
				form: {
					password: '',
					newpassword: '',
					surepassword: '',
				}
			}
		},
		methods: {
			async onRegister(){
				if(!this.form.password){
					uni.showToast({
						title: "请输入原密码",
						icon: 'none'
					});
					return
				}
				if(!this.form.newpassword){
					uni.showToast({
						title: "请输入新密码",
						icon: 'none'
					});
					return
				}
				if(this.form.newpassword != this.form.surepassword){
					uni.showToast({
						title: "两次密码不一致",
						icon: 'none'
					});
					return
				}
				let params = {
					password: md5.hex_md5(this.form.password),
					newpassword: md5.hex_md5(this.form.newpassword),
					surepassword: md5.hex_md5(this.form.surepassword),
				}
				
				let res = await this.$common.post('/app/user/xiugai', params);
				if(0 == res.code){
					uni.showToast({
						title:"修改成功",
						icon:'none'
					});
					setTimeout(()=>{
						uni.navigateBack();
					}, 1000);
				}else{
					uni.showToast({
						title:res.msg,
						icon:'none'
					})
				}
			},

		}
	}
</script>

<style lang="scss">
	.layoutBg {
		box-sizing: border-box;
		background-color: #f5f5f5;
		width: 100%;
		height: 100vh;
		padding-left: 50rpx;
		padding-right: 50rpx;
	}

	.title {
		color: #222;
		font-weight: bold;
		font-size: 50rpx;
		margin-top: 200rpx;
	}

	.phone {
		background-color: #ededed;
		border-radius: 10rpx;
		width: 100%;
		height: 90rpx;
		margin-top: 30rpx;
		align-items: center;
		.etLabel {
			width: 150rpx;
			height: 90rpx;
			line-height: 90rpx;
			font-size: 36rpx;
			color: #222;
			text-align: center;
		}
		
		.et {
			height: 100rpx;
			padding-right: 20rpx;
			padding-left: 20rpx;
			line-height: 100rpx;
			font-size: 28rpx;
			flex: 1;
		}
		
		.btn-custom{
			background-image: linear-gradient(to right, #9fe9ff, #ab7aff);
			border-radius: 50rpx;
			width: 200rpx;
			height: 100%;
			line-height: 100%;
			text-align: center;
			color:white;
		}
		
	}

	
	.spaceBetween {
		justify-content: space-between;
	}

	.textButton {
		height: 50rpx;
		line-height: 50rpx;
		padding: 20rpx 20rpx;
		color: #666;
		font-size: 30rpx;
	}

	.privacy {
		font-size: 30rpx;
		color: #ab7aff;
	}

	.privacyNo {
		font-size: 30rpx;
		color: #666;
	}

	.privacyView {
		align-items: center;
	}
	
	.btn-login{
		margin-top: 100rpx;
		box-sizing: border-box;
		background-image: linear-gradient(to right, #9fe9ff, #ab7aff);
		border-radius: 40rpx;
		width: 100wh;
		height: 80rpx;
		line-height: 80rpx;
		text-align: center;
		color:white;
	}
</style>